from os.path import join, dirname
from PyQt5.QtCore import QSize
from PyQt5.QtGui import QMovie, QPalette
from PyQt5.QtWidgets import QWidget, QApplication, QLabel

class MyWidget(QWidget):
    def __init__(self):
        super(MyWidget, self).__init__()
        self.setWindowTitle("设置gif图片为窗口背景示例")
        self.resize(800, 600)
        self.label = QLabel(self)
        self.label.setStyleSheet("background-color: rgb(255, 255, 255);")
        gif_file = join(dirname(__file__), "res", "test.gif")
        movie = QMovie(gif_file)
        self.label.setMovie(movie)
        movie.setScaledSize(QSize(self.width(), self.height()))
        movie.start()
        palette = self.palette()
        palette.setBrush(QPalette.Background,
                         self.label.palette().brush(QPalette.Background))
        self.setPalette(palette)

app = QApplication([])
w = MyWidget()
w.show()
app.exec_()